package com.lagou.springboot.work.controller;

import com.github.pagehelper.PageInfo;
import com.lagou.springboot.work.entity.ArticleEntity;
import com.lagou.springboot.work.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/findById")
    public String findById(int id, Model model) {
        ArticleEntity articleEntity = articleService.findById(id);
        model.addAttribute("data",articleEntity);
        return "login";
    }

    @RequestMapping("/findPage/{pageNum}")
    public String findAll(@PathVariable("pageNum") int pageNum, Model model) {
        PageInfo<ArticleEntity> page = articleService.findPages(pageNum);
        model.addAttribute("data",page);
        return "index";
    }

}
